home *** CD-ROM | disk | FTP | other *** search
- unit IDERunU;
-
- interface
-
- uses
- WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ExtCtrls;
-
- type
- TForm1 = class(TForm)
- chkDelphi1: TCheckBox;
- chkDelphi32: TCheckBox;
- chkDelphiDebugger: TCheckBox;
- chkDelphiRunning: TCheckBox;
- chkDelphiLaunchedMe: TCheckBox;
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- uses
- {$ifdef Win32}
- Registry,
- {$endif}
- IniFiles;
-
- {$R *.DFM}
-
- function Delphi1Exists: Boolean;
- var
- LibName: String;
- begin
- with TIniFile.Create('DELPHI.INI') do
- try
- LibName := ReadString('Library', 'ComponentLibrary', '');
- Result := (LibName <> '') and FileExists(LibName)
- finally
- Free
- end;
- end;
-
- {$ifdef Win32}
- function Delphi32Exists: Boolean;
- var
- Reg: TRegistry;
- Keys, Values: TStrings;
- KeyLoop, ValueLoop: Integer;
- const
- DelphiPath = 'Software\Borland\Delphi\';
- begin
- Result := False;
- Reg := TRegistry.Create;
- Keys := TStringList.Create;
- Values := TStringList.Create;
- try
- Reg.RootKey := HKEY_LOCAL_MACHINE;
- if Reg.OpenKey(DelphiPath, False) and Reg.HasSubKeys then
- begin
- //There may be more than one Delphi section
- Reg.GetKeyNames(Keys);
- Reg.CloseKey;
- for KeyLoop := 0 to Keys.Count - 1 do
- if not Result and Reg.OpenKey(DelphiPath + Keys[KeyLoop], False) then
- try
- Reg.GetValueNames(Values);
- for ValueLoop := 0 to Values.Count - 1 do
- begin
- Result := (Pos('Delphi', Values[ValueLoop]) > 0) and
- FileExists(Reg.ReadString(Values[ValueLoop]));
- if Result then Break
- end;
- finally
- Reg.CloseKey
- end
- end
- finally
- Reg.Free;
- Keys.Free;
- Values.Free
- end
- end;
- {$endif}
-
- {$ifndef WIN32}
- type
- { Used by TDebugRec }
- TExceptionKind = (evNull, evRaise, evExcept, evFinally,
- evUnexpected, evTerminate);
-
- { Used by DebuggerRunning }
- PDebugRec = ^TDebugRec;
- TDebugRec = record
- dhMagic1,
- dhZero,
- dhMagic2,
- dhHookProc,
- dhDebugHooked: Longint;
- dhKind: Word; { Use TExceptionKind enumerated type above }
- dhAddr,
- dhCookie,
- dhNameLen,
- dhName,
- dhMsgLen,
- dhMsg,
- dhWantException,
- dhDoneExcept: Longint;
- end;
-
- const
- DebuggerHook = $24; { Offset in DS of pointer to debugger data }
- {$endif}
-
- { Checks if debugger is active (it swallows notifications) }
- function DelphiDebuggerRunning: Boolean;
- begin
- {$ifndef WIN32}
- Result := (PrefixSeg <> 0) and
- (LoWord(PDebugRec(Ptr(DSeg, DebuggerHook)^)^.dhDebugHooked) <> 0);
- { You can dispense with all these type definitions }
- { by using the following piece of code instead: }
- { Result := Bool(PrefixSeg) and Bool(PWordArray(MemL[DSeg:36])^[8]) }
- {$else}
- Result := DebugHook <> 0;
- {$endif}
- end;
-
- function DelphiRunning: Boolean;
- begin
- Result :=
- Bool(FindWindow('TAppBuilder', nil)) and
- Bool(FindWindow('TPropertyInspector', nil)) and
- Bool(FindWindow('TMenuBuilder', nil)) and
- Bool(FindWindow('TAlignPalette', nil));
- end;
-
- function DelphiLaunchedMe: Boolean;
- var
- Wnd: HWnd;
- CCaption: array[0..255] of Char;
- FileName, Caption: String;
- begin
- Result := False;
- if DelphiRunning then
- begin
- { Get Delphi's main window }
- Wnd := FindWindow('TAppBuilder', nil);
- { Read its caption }
- GetWindowText(Wnd, CCaption, SizeOf(CCaption));
- { Translate the C string into a Pascal string, upper cased }
- Caption := UpperCase(StrPas(CCaption));
- { Find the root part of this project name... }
- FileName := ExtractFileName(Application.ExeName);
- { ...without the extension }
- FileName := Copy(FileName, 1, Length(FileName) - 4);
- { If Delphi has my project name in its caption, then we win }
- Result := Pos(FileName, Caption) <> 0;
- end
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- chkDelphi1.Checked := Delphi1Exists;
- {$ifdef Win32}
- chkDelphi32.Checked := Delphi32Exists;
- {$else}
- chkDelphi32.Enabled := False;
- {$endif}
- chkDelphiRunning.Checked := DelphiRunning;
- chkDelphiDebugger.Checked := DelphiDebuggerRunning;
- chkDelphiLaunchedMe.Checked := DelphiLaunchedMe
- end;
-
- end.